package com.ciklum.robotester.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * Created by miy on 7/7/2014.
 */
public class MainPanel extends JPanel {
    private INavigator workspaceComponent = new WorkspaceComponent();
    public MainPanel() {
        setLayout(new BorderLayout());
        JPanel buttonsPanel = new JPanel();
        buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
        buttonsPanel.add(Box.createHorizontalStrut(10));
        buttonsPanel.add(fixComponentSize(new JButton(new OpenAction()),new Dimension(26,26)));
        buttonsPanel.add(Box.createHorizontalStrut(15));
        buttonsPanel.add(fixComponentSize(new JButton(new AddAction()),new Dimension(26,26)));
        buttonsPanel.add(Box.createHorizontalStrut(2));
        buttonsPanel.add(fixComponentSize(new JButton(new UpAction()),new Dimension(26,26)));;
        buttonsPanel.add(Box.createHorizontalStrut(2));
        buttonsPanel.add(fixComponentSize(new JButton(new DownAction()),new Dimension(26,26)));;
        buttonsPanel.add(Box.createHorizontalStrut(2));
        buttonsPanel.add(fixComponentSize(new JButton(new RemoveAction()),new Dimension(26,26)));;

        buttonsPanel.add(Box.createHorizontalStrut(20));
        buttonsPanel.add(fixComponentSize(new JButton(new RunAll()),new Dimension(26,26)));;
        buttonsPanel.add(Box.createHorizontalStrut(2));
        buttonsPanel.add(fixComponentSize(new JButton(new RunSelected()),new Dimension(26,26)));;
        buttonsPanel.add(Box.createHorizontalGlue());
        add(buttonsPanel, BorderLayout.NORTH);
        JSplitPane jSplitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        jSplitPane.add(workspaceComponent.getComponent(),JSplitPane.TOP);
        jSplitPane.add(new JScrollPane(new JEditorPane()),JSplitPane.BOTTOM);
        jSplitPane1.add(jSplitPane,JSplitPane.TOP);
        jSplitPane1.add(new JScrollPane(new JEditorPane()),JSplitPane.BOTTOM);


        add(jSplitPane1);


    }

    private Component fixComponentSize(Component jButton,Dimension dimension) {
        jButton.setMaximumSize(dimension);
        jButton.setMinimumSize(dimension);
        jButton.setSize(dimension);
        jButton.setPreferredSize(dimension);
        return jButton;
    }


    class AddAction extends AbstractAction {
        AddAction() {
            putValue(SMALL_ICON, new ImageIcon(getClass().getClassLoader().getResource("com/ciklum/robotester/img/plus.png")));
        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }

    class UpAction extends AbstractAction {
        UpAction() {
            putValue(SMALL_ICON, new ImageIcon(getClass().getClassLoader().getResource("com/ciklum/robotester/img/arrow_up.png")));
            putValue(TOOL_TIP_TEXT_KEY,"Move up selected");
        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }

    class DownAction extends AbstractAction {
        DownAction() {
            putValue(SMALL_ICON, new ImageIcon(getClass().getClassLoader().getResource("com/ciklum/robotester/img/arrow_down.png")));
            putValue(TOOL_TIP_TEXT_KEY,"Move down selected");
        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }

    class RemoveAction extends AbstractAction {
        RemoveAction() {
            putValue(SMALL_ICON, new ImageIcon(getClass().getClassLoader().getResource("com/ciklum/robotester/img/delete.png")));
            putValue(TOOL_TIP_TEXT_KEY,"Remove selected from workspace");
        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }

    class RunAll extends AbstractAction {
        RunAll() {
            putValue(SMALL_ICON, new ImageIcon(getClass().getClassLoader().getResource("com/ciklum/robotester/img/run_copy.png")));
            putValue(TOOL_TIP_TEXT_KEY,"Run All...");
        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }


    class RunSelected extends AbstractAction {
        RunSelected() {
            putValue(SMALL_ICON, new ImageIcon(getClass().getClassLoader().getResource("com/ciklum/robotester/img/gnome_media_playback_start.png")));
            putValue(TOOL_TIP_TEXT_KEY,"Run slected...");
        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }


    class OpenAction extends AbstractAction {
        OpenAction() {
            putValue(SMALL_ICON, new ImageIcon(getClass().getClassLoader().getResource("com/ciklum/robotester/img/folder.png")));
            putValue(TOOL_TIP_TEXT_KEY,"Open workspace");
        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }






}
